package com.working.libnet

import retrofit2.Call
import retrofit2.CallAdapter
import retrofit2.Retrofit
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type

class ApiResponseCallAdapter : CallAdapter.Factory() {
    override fun get(
        returnType: Type,
        annotations: Array<out Annotation>,
        retrofit: Retrofit
    ): CallAdapter<*, *>? {
        if (Result::class.java != getRawType(returnType)) return null
        if (returnType !is ParameterizedType) {
            throw IllegalStateException(
                "Result return type must be parameterized as Result<Foo> or Result<out Foo>"
            )
        }
        val responseType = getParameterUpperBound(0, returnType)
        return object : CallAdapter<Any, Any> {
            override fun responseType() = responseType

            override fun adapt(call: Call<Any>): Any {
                TODO("Not yet implemented")
            }

        }
    }
}